﻿using Fine.Collections.Cont;
using Fine.Collections.Intf;
using Fine.TestUtils;
using NUnit.Framework;



namespace Fine.Collections.Views
{
    [TestFixture]
    public class RCollectionAdaptor_test
    {

        [Test]
        public void Test_Count()
        {
            var adaptor = MakeSimpleCollectionAndAdapter();

            adaptor.IsEmpty       ._false_();
            adaptor.IsNotEmpty    ._true_();
            adaptor.Count         ._equals_(3);
        }


        [Test]
        public void Test_Find()
        {
            var adaptor = MakeSimpleCollectionAndAdapter();

            adaptor.Find(x => x == "100001").Item  ._equals_("100001");
            adaptor.Find(x => x == "200002").Item  ._equals_("200002");
            adaptor.Find(x => x == "300003").Item  ._equals_("300003");

            adaptor[x => x == "100001"]            ._equals_("100001");
            adaptor[x => x == "200002"]            ._equals_("200002");
            adaptor[x => x == "300003"]            ._equals_("300003");
        }


        [Test]
        public void Test_ProcessAll()
        {
            var adaptor = MakeSimpleCollectionAndAdapter();

            var list2 = new ArrList<string>(1, 3);

            adaptor.ProcessAll(list2.Add);

            list2.ToArray()   ._array_("100001", "200002", "300003");
        }


        [Test]
        public void Test_Iterator()
        {
            var adaptor = MakeSimpleCollectionAndAdapter();

            var it = adaptor.TakeIterator();

            it.Next()     ._true_();
            it.Current    ._equals_("100001");
            it.Next()     ._true_();
            it.Current    ._equals_("200002");
            it.Next()     ._true_();
            it.Current    ._equals_("300003");
            it.Next()     ._false_();
        }


        private static RCollectionAdaptor<RList<long>, long, string> MakeSimpleCollectionAndAdapter() 
        {
            var source = new ArrList<long>(1)
                         {
                             100001, 200002, 300003
                         };
            return new RCollectionAdaptor<RList<long>,long,string>(source, x => x.ToString());
        }

    }
}
